<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    
</head>
<body>
    <input type="button" value="发送验证码" id="sendCode">
    <script>
        var timer;
        var s=20;
        var btn=document.getElementById("sendCode");
        function show(){
            if(s<0){
                clearInterval(timer);
                btn.disabled=false;//启用按钮
                btn.value=`发送验证码`;
                s=20;
            }else{
                btn.disabled=true;//禁用按钮
                btn.value=`${s}秒后重发`;
                s--;
               
            }
           
        }
        btn.onclick=function(){
            timer=setInterval(show,500);
        };
    </script>
</body>
</html>